package jsc.acid;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;

/**
 * This class only provides a more comfortable way to deal with a Collection (ArrayList) of Dictionnary.
 * 
 * @author Alec Ermis, Maxime Rihouey
 *
 */
public class GroupOfDictionary {

	HashSet<Dictionary> group;

	// constructeur
	public GroupOfDictionary(){
		group = new HashSet<Dictionary>();
	}

	public GroupOfDictionary(Dictionary d){
		this();
		group.add(d);
	}

	public GroupOfDictionary(HashSet<Dictionary> group){
		this.group = group;
	}

	// getters
	public HashSet<Dictionary> getList(){
		return group;
	}

	// methods
	/**
	 * add a dictionary to the group
	 */
	public void add(Dictionary d){
		group.add(d);
	}

	/**
	 * test wether one of the group of dictionary contains the specified String
	 * @param word
	 * @return
	 */
	public boolean contains(String word){
		for(Dictionary d: group){
			if(d.contains(word)) return true;
		}
		return false;
	}


	/*
	 * Test
	 */
	public static void main(String[] args) {

		System.out.println("Avec ABR");
		boolean useABR = true;
		System.out.println("###################### Test Positif ################");
		try {

			// test positif
			GroupOfDictionary dictionaries = new GroupOfDictionary();
			dictionaries.add(new Dictionary(new File("dicts/dictTest"), useABR));
			dictionaries.add(new Dictionary(new File("dicts/english"), useABR));

			System.out.println(dictionaries.contains(""));
			System.out.println(dictionaries.contains("abalones"));


		} catch (IOException e) {
			System.out.println("Impossible de trouver le fichier.");
		}

		System.out.println("###################### Test Negatif ################");
		try {

			// test negatif
			GroupOfDictionary dictionaries = new GroupOfDictionary();
			dictionaries.add(new Dictionary(new File("dicts/dictTest"), useABR));
			dictionaries.add(new Dictionary(new File("dicts/english"), useABR));

			System.out.println(dictionaries.contains(""));
			System.out.println(dictionaries.contains("abalones"));


		} catch (IOException e) {
			System.out.println("Impossible de trouver le fichier.");
		}

		System.out.println("Sans ABR");
		useABR = false;
		System.out.println("###################### Test Positif ################");
		try {

			// test positif
			GroupOfDictionary dictionaries = new GroupOfDictionary();
			dictionaries.add(new Dictionary(new File("dicts/dictTest"), useABR));
			dictionaries.add(new Dictionary(new File("dicts/english"), useABR));

			System.out.println(dictionaries.contains(""));
			System.out.println(dictionaries.contains("abalones"));


		} catch (IOException e) {
			System.out.println("Impossible de trouver le fichier.");
		}

		System.out.println("###################### Test Negatif ################");
		try {

			// test negatif
			GroupOfDictionary dictionaries = new GroupOfDictionary();
			dictionaries.add(new Dictionary(new File("dicts/dictTest"), useABR));
			dictionaries.add(new Dictionary(new File("dicts/english"), useABR));

			System.out.println(dictionaries.contains(""));
			System.out.println(dictionaries.contains("abalones"));


		} catch (IOException e) {
			System.out.println("Impossible de trouver le fichier.");
		}
	}
}
